<template>
    <div>
        <button @click="sum++">+</button>sum：{{sum}}
        <br>
    </div>
</template>

<script>
import {ref,onBeforeMount,onMounted,onBeforeUpdate,onUpdated,onBeforeUnmount,onUnmounted} from 'vue'
export default {
    name: 'Demo',
    setup(){
        let sum = ref(0)
        //通过组合式API的形式去使用生命周期钩子
        onBeforeMount(()=>{
            console.log('---onBeforeMount---')
        })
        onMounted(()=>{
            console.log('---onMounted---')
        })
        onBeforeUpdate(()=>{
            console.log('---onBeforeUpdate---')
        })
        onUpdated(()=>{
            console.log('---onUpdated---')
        })
        onBeforeUnmount(()=>{
            console.log('---onBeforeUnmount---')
        })
        onUnmounted(()=>{
            console.log('---onUnmounted---')
        })

        return {
            sum,

        }
    },
    // beforeCreate() {
    //     console.log('---beforeCreate---')
    // },
    // created() {
    //     console.log('---created---')
    // },
    // beforeMount() {
    //     console.log('---beforeMount---')
    // },
    // mounted() {
    //     console.log('---mounted---')
    // },
    // beforeUpdate(){
    //     console.log('---beforeUpdate---')
    // },
    // updated() {
    //     console.log('---updated---')
    // },
    // beforeUnmount() {
    //     console.log('---beforeUnmount---')
    // },
    // unmounted() {
    //     console.log('---unmounted---')
    // },
}
</script>

<style>
#app {
    font-family: Avenir, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: center;
    color: #2c3e50;
    margin-top: 60px;
}
</style>
